package cj.web.kly.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.kly.domain.Member;

/**
 * 
 * @author 
 *
 */
@DAO
public interface MemberDAO{
	
    @SQL("SELECT * FROM Member WHERE id=:1 ")
    Member queryById(int id);
    
    @SQL("SELECT * FROM Member WHERE phone=:1 ")
    Member queryByPhone(String phone);
    
    @SQL("INSERT INTO Member (phone,name,pwd,sex,age,career,isError,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.phone,:t.name,:t.pwd,:t.sex,:t.age,:t.career,0,1,:t.createUser,now(),:t.updateUser,now()) ")
    void create(@SQLParam("t") Member member);
    
	@SQL("UPDATE Member SET phone=:t.phone,name=:t.name,pwd=:t.pwd,sex=:t.sex,age=:t.age,career=:t.career,updateUser=:t.updateUser,updateAt=NOW() WHERE id=:t.id ")
    void update(@SQLParam("t") Member member);
    
    @SQL("UPDATE Member SET deleteFlag=0 WHERE id=:1 ")
    void deleteById(int id);
    
    @SQL("UPDATE Member SET isError=0,pwd=:2 WHERE id=:1 ")
    void updateErrorById(int id,String pwd);

    @SQL("SELECT * FROM Member WHERE deleteFlag=1 #if(:t.name!=null){ AND name LIKE '%##(:t.name)%' } #if(:t.phone!=null){ AND phone LIKE '%##(:t.phone)%' } ORDER BY createAt DESC LIMIT :t.start,:t.length ")
	List<Member> queryByPhone(@SQLParam("t")Member member);

    @SQL("SELECT count(0) FROM Member WHERE deleteFlag=1 #if(:t.name!=null){ AND name LIKE '%##(:t.name)%' } #if(:t.phone!=null){ AND phone LIKE '%##(:t.phone)%' } ")
	int queryByPhoneSize(@SQLParam("t")Member member);
}